package com.zhilianbao.leyaogo.view.widgets;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhilianbao.leyaogo.R;

import java.util.List;

/**
 * Created by gyt on 2016/12/30
 * 商品详情页面中商品标签的布局
 */
public class GoodsSignLayout extends FlowLayout {
    private final Context mContext;

    public GoodsSignLayout(Context context) {
        this(context, null);
    }

    public GoodsSignLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GoodsSignLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
    }

    public void setSignData(List<String> lists) {
        for (int i = 0; i < lists.size(); i++) {
            String goodsSign = lists.get(i);
            final TextView signTextView = new TextView(mContext);
            signTextView.setText(goodsSign);
            Drawable drawable = getResources().getDrawable(R.drawable.ic_sign);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            signTextView.setCompoundDrawablePadding(dip2px(mContext, 4));
            signTextView.setCompoundDrawables(drawable, null, null, null);
            signTextView.setTextColor(mSpecTextColor);
            signTextView.setTextSize(mSpecTextSize);
            LinearLayout.LayoutParams lLp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            this.addView(signTextView, lLp);
        }
    }
}
